import {clerkMiddleware} from "@clerk/nextjs/server";

export default clerkMiddleware(async (auth, request, event) => {
    const userInfo = auth()
    if (!userInfo.userId) {
        return userInfo.redirectToSignIn({
            returnBackUrl: request.url
        })
    }
    // 发起一个请求
    const res = await fetch(process.env.API_ADDRESS + "/user", {
        method: "POST",
        headers: {
            "Content-Type": "application/json"
        },
        body: JSON.stringify({
            userId: userInfo.userId
        })
    })
    // 获取结果
    const data = await res.json()
    console.log("file: middleware.ts: 10; ~ clerkMiddleware ~ userId:", data)
});

export const config = {
    matcher: ["/"],
};